package model.tokens;

import java.util.Stack;

import state.TabState;

import model.expression.AbstractExpression;
import model.parser.ParserException;
import model.parser.ParsingData;
/**
 * Token that is a right parenthesis
 * 
 * @author KevinWang Chris James Misha Lavrov
 * 
 * @param <T>
 *            any object
 */
public class RightParenToken extends AbstractToken {

	public RightParenToken(String value, ParsingData parsingData) {
	}

	/**
	 * when right parenthesis is encountered, it will continue to pop operators
	 * off the operator stack until it reaches a LeftToken/FunctionToken. If a
	 * functionToken is reached, then a function needs to make expression. If a
	 * normal LeftParenthesis is reached, then it is just popped off.
	 */
	@Override
	//done Via shunting yard
	public void convertToPostFix(Stack<AbstractToken> opStack,
			Stack<AbstractExpression> outStack,TabState ts,Stack<AbstractExpression> out) {
		if (opStack.isEmpty())
			throw ParserException.BAD_SYNTAX;

		while (!(opStack.peek() instanceof LeftParenToken)) {
			((OperatorToken) opStack.pop()).makeExpression(outStack,out);

			if (opStack.isEmpty())
				throw ParserException.BAD_SYNTAX;
		}
	opStack.pop();
	}
}
